cmake_minimum_required(VERSION 3.10)

#project(modbus)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Os -fPIC")

aux_source_directory(./src SRC)
aux_source_directory(../gw/src GW_SRC)

#include_directories
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../serialProxy/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../db/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../gw/include)
#library_directories
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)

#add_executable(modbus ${SRC}) # 生成可执行文件
#add_library(modbus STATIC ${SRC}) # 生成静态库
add_library(modbus SHARED ${SRC} ${GW_SRC}) # 生成动态库或共享库
SET_TARGET_PROPERTIES(modbus PROPERTIES VERSION 1.0.0 SOVERSION 1)

#TARGET_LINK_LIBRARIES(modbus liblogger.so libcommon.so libdb.so)

install(TARGETS modbus LIBRARY DESTINATION ${CMAKE_LIBRARY_PATH})

add_custom_command(TARGET modbus
        POST_BUILD
        COMMAND echo "modbus builded finished."
        COMMAND ${CMAKE_STRIP} "$<TARGET_FILE:modbus>"
        #COMMAND ${CMAKE_COMMAND} -E copy  "${CMAKE_CURRENT_SOURCE_DIR}/include/global.h" ${CMAKE_INCLUDE_PATH}/global.h
#        COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:modbus>  ${CMAKE_LIBRARY_PATH}/libmodbus.so 
#        COMMENT  "modbus is install finished"
       )